package com.icity.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import com.icity.entity.AllSumary;
import com.icity.entity.Application;
import com.icity.entity.EquipmentDistribution;
import com.icity.entity.PartnerMsg;
import com.icity.entity.RegisteredUse;
import com.icity.entity.ResourceDistribution;
import com.icity.entity.StatisticalSummary;
import com.icity.entity.journalBookReadBorrow;
import com.icity.entity.journalBookStatistical;

/**
 * 分类管理
 * @author apple
 */
@Mapper
public interface StatisticalSummaryMapper {


	//@Select("select * from tbl_icity_statistical_summary where type=#{type} and application_unique_code=#{application_unique_code} and partner_id=#{partner_id}")


	@Select(
			"<script>"
					+"select * from tbl_icity_statistical_summary where 1 = 1 "
					+ "<if test='type != null'>"
					+ " and type =#{type} "
					+ "</if>"

					+ "<if test='partner_id != null'>"
					+ " and partner_id = #{partner_id}"
					+ "</if>"
					+ "<if test='application_unique_code != null'>"
					+ " and application_unique_code = #{application_unique_code}"
					+ "</if>"
					+ " </script>"
			)
	List<StatisticalSummary> getAll(Map<Object, Object> map);

	//@Select("select * from tbl_icity_statistical_summary where type=#{type} and application_unique_code=#{application_unique_code} and partner_id=#{partner_id}")
	//List<Map<String,Object>> getAll(Map<Object, Object> map);
	@Select("select unique_code,operate_name,name from tbl_partner_msg where 1=1 and is_partner_or_user=1 and (unique_code=#{unique_code} or parent_code=#{unique_code})")
	List<PartnerMsg> getPartner(String unique_code);
	@Select("select * from tbl_application where partner_id=#{unique_code} and platform_type=#{type} ")
	List<Application> getApplication(Map<Object, Object> map);





	@Select(
			"<script>"
					+"select location_num,province from tbl_icity_equipment_distribution where 1 = 1 "
					+ "<if test='application_unique_code != null'>"
					+ " and application_unique_code =#{application_unique_code} "
					+ "</if>"
					+ "<if test='type != null'>"
					+ " and type =#{type} "
					+ "</if>"
					+ "<if test='partner_id != null'>"
					+ " and partner_id = #{partner_id}"
					+ "</if>"
					+ " </script>"
			)
	List<EquipmentDistribution> getEquipmentDistribution(Map<Object, Object> map);
    @Select("select registered_type,registered_user_num from tbl_icity_registered_user where application_unique_code=#{application_unique_code} and partner_id=#{partner_id}")
	List<RegisteredUse> getAppRegisteredCount(Map<Object, Object> map);
  //  @Select("select resources_package_journal_num,resources_package_book_num,resources_package_news_num,resources_package_audio_num,resources_package_video_num from tbl_icity_resource_distribution where application_unique_code=#{application_unique_code} and partner_id=#{partner_id}")
    @Select(
			"<script>"
					+"select resources_package_journal_num,resources_package_book_num,"
					+ "resources_package_news_num,resources_package_audio_num,resources_package_video_num from tbl_icity_resource_distribution where 1 = 1 "
					+ "<if test='application_unique_code != null'>"
					+ " and application_unique_code =#{application_unique_code} "
					+ "</if>"

					+ "<if test='partner_id != null'>"
					+ " and partner_id = #{partner_id}"
					+ "</if>"
					+ " </script>"
			)
 ResourceDistribution getResourcesDistribution(Map<Object, Object> map);

    @Select("select resource_num,resource_read_num,resource_borrow_num  from tbl_icity_journal_statisticall where type=#{type} and application_unique_code=#{application_unique_code} and partner_id=#{partner_id} and resource_type=#{resource_type}")
	List<journalBookStatistical> getAlljournalBook(Map<Object, Object> map);
	@Select("select resource_name,unique_code from tbl_icity_journal_borrow_read where type=#{type} and application_unique_code=#{application_unique_code} and partner_id=#{partner_id} and resource_type=#{resource_type} order by resource_read_num desc,order by resource_borrow_num desc limit 10")
	List<journalBookReadBorrow> getjournalBookreadbroow(Map<Object, Object> map);
	@Select("select resource_name,unique_code from tbl_icity_journal_borrow_read where type=#{type} and application_unique_code=#{application_unique_code} and partner_id=#{partner_id} and resource_type=#{resource_type} order by resource_down_num desc limit 10")
	List<journalBookReadBorrow> getjournalBookdownreadbroow(Map<Object, Object> map);
	@Select(
			"<script>"
					+"select resources_package_journal_num,resources_package_book_num,"
					+ "resources_package_news_num,resources_package_audio_num,resources_package_video_num from tbl_icity_resource_distribution where 1 = 1 "
					+ "<if test='application_unique_code != null'>"
					+ " and application_unique_code =#{application_unique_code} "
					+ "</if>"

					+ "<if test='partner_id != null'>"
					+ " and partner_id = #{partner_id}"
					+ "</if>"
					+ " </script>"
			)
	ResourceDistribution getResourceDistribution1(Map<Object, Object> map);
	@Select(
			"<script>"
					+"select province from tbl_icity_equipment_distribution where 1 = 1 "
					+ "<if test='application_unique_code != null'>"
					+ " and application_unique_code =#{application_unique_code} "
					+ "</if>"

					+ "<if test='partner_id != null'>"
					+ " and partner_id = #{partner_id}"
					+ "</if>"
					+ " </script>"
			)
	List<String> getEquipmentProvinceDistribution(Map<Object, Object> map);
	@Select(
			"<script>"
					+"select location_num from tbl_icity_equipment_distribution where 1 = 1 "
					+ "<if test='application_unique_code != null'>"
					+ " and application_unique_code =#{application_unique_code} "
					+ "</if>"

					+ "<if test='partner_id != null'>"
					+ " and partner_id = #{partner_id}"
					+ "</if>"
					+ " </script>"
			)
	List<Integer> getEquipmentProvinceNumDistribution(Map<Object, Object> map);
	@Select(
			"<script>"
					+"select city from tbl_icity_equipment_distribution where 1 = 1 "
					+ "<if test='application_unique_code != null'>"
					+ " and application_unique_code =#{application_unique_code} "
					+ "</if>"

					+ "<if test='partner_id != null'>"
					+ " and partner_id = #{partner_id}"
					+ "</if>"
					+ " </script>"
			)
	List<String> getEquipmentcityDistribution(Map<Object, Object> map);
	@Select(
			"<script>"
					+"select num from tbl_icity_system_traffic where 1 = 1 "
					+ "<if test='application_unique_code != null'>"
					+ " and application_unique_code =#{application_unique_code} "
					+ "</if>"

					+ "<if test='partner_id != null'>"
					+ " and partner_id = #{partner_id}"
					+ "</if>"
					+ " </script>"
			)
	List<Integer> getSystemTraffic(Map<Object, Object> map);

	@Select("select * from tbl_statistics_all")
	AllSumary getAllSumary();

}
